package com.guoxin.thread.transport;

/**
 * 写入线程
 *
 * @author guoxin
 * @date 2019/6/28
 */
public class InputThread extends Thread {
    private final Resource resource;

    public InputThread(Resource resource) {
        this.resource = resource;
    }

    @Override
    public void run() {
        int count = 0;
        while (true) {
            synchronized (resource) {
                if (resource.flag) {
                    try {
                        resource.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                if (count % 2 == 0) {
                    resource.name = "张三";
                    resource.six = "男";
                } else {
                    resource.name = "李四";
                    resource.six = "女";
                }
                count++;
                resource.flag = true;
                resource.notify();
            }
        }
    }
}
